import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2024-06-01
 * Time: 10:39
 */
public class Test {


    public static void main(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.addLast(6);
        mySingleList.addLast(2);
        mySingleList.addLast(8);
        // mySingleList.addLast(45);
        //mySingleList.addIndex(2, 56);
        //mySingleList.remove(45);
        //System.out.println(mySingleList.findKthToTail(2).val);
        //mySingleList.partition();
        mySingleList.show();
    }

    public static void main4(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        List<Integer> linkedList = new LinkedList<>(list);
        System.out.println(linkedList);
        // for-each遍历
        for (Integer x: linkedList) {
            System.out.print(x + " ");
        }
        System.out.println();
        // 迭代器正向遍历
        ListIterator<Integer> lit = linkedList.listIterator();
        while(lit.hasNext()) {
            System.out.print(lit.next() + " ");
        }
        System.out.println();
        // 迭代器反向遍历
        ListIterator<Integer> lit2 = linkedList.listIterator(linkedList.size());
        while (lit2.hasPrevious()) {
            System.out.print(lit2.previous() + " ");
        }
        System.out.println();
        String S = "111";
        System.out.println(Integer.parseInt(S));
    }
    public static void main3(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        myLinkedList.addLast(1);
        myLinkedList.addLast(1);
        myLinkedList.addLast(3);
        myLinkedList.addLast(1);
        myLinkedList.addLast(1);
        myLinkedList.display();
        myLinkedList.removeAllKey(1);
        myLinkedList.display();
//        myLinkedList.addIndex(2, 9);
//        myLinkedList.display();
//        myLinkedList.remove(9);
//        myLinkedList.display();
    }

    // 合并两个有序链表
    public static MySingleList.ListNode mergeTwoLists(MySingleList.ListNode list1, MySingleList.ListNode list2) {
        MySingleList.ListNode newHead = new MySingleList.ListNode(-1);
        MySingleList.ListNode tmpH = newHead;
        while(list1 != null && list2 != null) {
            if(list1.val < list2.val) {
                tmpH.next = list1;
                list1 = list1.next;
                tmpH = tmpH.next;
            }else {
                tmpH.next = list2;
                list2 = list2.next;
                tmpH = tmpH.next;
            }
        }
        if(list1 != null) {
            tmpH.next = list1;
        }
        if(list2 != null) {
            tmpH.next = list2;
        }
        return newHead.next;
    }

    public static void main2(String[] args) {
        MySingleList mySingleList1 = new MySingleList();
        MySingleList mySingleList2 = new MySingleList();
        mySingleList1.addLast(12);
        mySingleList1.addLast(23);
        mySingleList1.addLast(34);
        mySingleList1.addLast(45);
        mySingleList2.addLast(21);
        mySingleList2.addLast(24);
        mySingleList2.addLast(25);
        mySingleList2.addLast(26);
        mySingleList2.addLast(81);
        MySingleList.ListNode ret = mergeTwoLists(mySingleList1.head, mySingleList2.head);
        MySingleList.ListNode cur = ret;
        while(cur != null) {
            System.out.print(cur.val + " ");
            cur = cur.next;
        }
        System.out.println();
    }
    public static void main1(String[] args) {
        MySingleList mySingleList = new MySingleList();
        // mySingleList.createList();
        mySingleList.addLast(12);
        mySingleList.addLast(23);
        mySingleList.addLast(34);
        mySingleList.addLast(45);
        mySingleList.addLast(56);
        // mySingleList.addIndex(9, 99);
        // mySingleList.remove(56);
        mySingleList.show();
        // mySingleList.reverseList();
        // MySingleList.ListNode ret1 = mySingleList.middleNode(mySingleList.head);
       // System.out.println(ret1.val);
        MySingleList.ListNode ret2 = mySingleList.findKthToTail(5);
        System.out.println(ret2.val);
    }
}
